<script setup lang="ts">
import type {AuthPageLayoutType} from '@/typings/core';
import type {JcxDropdownMenuItem} from '@/components/common/shadcn';

import {computed} from 'vue';

import {InspectionPanel, PanelLeft, PanelRight} from '@/plugins/iconify';
import {$t} from '@/locales/effects';
import {
  preferences,
  updatePreferences,
  usePreferences,
} from '@/preferences/effects';
import {JcxDropdownRadioMenu, JcxIconButton} from '@/components/common/shadcn';

defineOptions({
  name: 'AuthenticationLayoutToggle',
});

const menus = computed((): JcxDropdownMenuItem[] => [
  {
    icon: PanelLeft,
    label: $t('authentication.layout.alignLeft'),
    value: 'panel-left',
  },
  {
    icon: InspectionPanel,
    label: $t('authentication.layout.center'),
    value: 'panel-center',
  },
  {
    icon: PanelRight,
    label: $t('authentication.layout.alignRight'),
    value: 'panel-right',
  },
]);

const {authPanelCenter, authPanelLeft, authPanelRight} = usePreferences();

function handleUpdate(value: string) {
  updatePreferences({
    app: {
      authPageLayout: value as AuthPageLayoutType,
    },
  });
}
</script>

<template>
  <JcxDropdownRadioMenu
      :menus="menus"
      :model-value="preferences.app.authPageLayout"
      @update:model-value="handleUpdate"
  >
    <JcxIconButton>
      <PanelRight v-if="authPanelRight" class="size-4"/>
      <PanelLeft v-if="authPanelLeft" class="size-4"/>
      <InspectionPanel v-if="authPanelCenter" class="size-4"/>
    </JcxIconButton>
  </JcxDropdownRadioMenu>
</template>
